//
// Created by 31897 on 2021/11/5.
//

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> num;
vector<vector<int>> target;

int main(){
    int n;
    cin >> n;
    num.resize(n);
    target.resize(n);
    for(int i = 0;i<n;i++){
        target[i].resize(n);
        num[i].resize(n);
        for (int j = 0; j <= i; ++j) {
            cin >> num[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if(i==0) {
                target[i][j] = num[i][j];
            }
            else if(j==0){
                target[i][j]=target[i-1][j]+num[i][j];
            }
            else{
                target[i][j]=max(target[i-1][j],target[i-1][j-1])+num[i][j];
            }
        }
    }
    int max = 0;
    for (int i = 0; i < n; ++i) {
        if(max < target[n-1][i]){
            max = target[n-1][i];
        }
    }
    cout << max;
    return 0;
}